<?php
    header('Content-type:text/json');
    require "../connection.php";
    $id = $_POST['user_id'];
    $carts = $_POST['carts'];
   $cartsstr = json_decode($carts,$assoc= true);
    $return = 0;

    for($i=0,$len=count($cartsstr);$i<$len;$i++){
         $goods_num = $cartsstr[$i]['goods_num'];
         $ischecked = $cartsstr[$i]['ischecked'];
         if($ischecked==''){
            $ischecked=0;
          }
         $goods_id = $cartsstr[$i]['goods_id'];
         $user_id = $cartsstr[$i]['user_id'];
         if($goods_num>0){
            $sql = "update cart set goods_num= '$goods_num', ischecked = '$ischecked' where goods_id = '$goods_id' and user_id = '$user_id'";

         }else{
            $sql = "update cart set goods_num= '$goods_num',status=-1, ischecked='$ischecked' where goods_id = '$goods_id' and user_id = '$user_id'";
         }
         $result = $conn->doSql($sql);
         if($result){
            $return = $result;
         }
    }
    echo json_encode($return);

?>
